package com.biz.ssm.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Page<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	/** 内容 */
	private final List<T> content = new ArrayList<T>();

	/** 总记录数 */
	private long total;

	/** 总页数 **/
	private long totalPages;

	/** 总页数 **/
	private int pageSize;

	private int pageNumber;


	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	/**
	 * 初始化一个新创建的Page对象
	 */
	public Page() {
		this.total = 0L;
		this.pageSize = 10;
		this.pageNumber = 0;
		this.totalPages = 0;
	}

	/**
	 * @param content
	 *            内容
	 * @param total
	 *            总记录数
	 * @param pageable
	 *            分页信息
	 */
	public Page(List<T> content, long total, Pageable pageable) {
		this.content.addAll(content);
		this.setTotal(total);
		this.pageSize = pageable.getPageSize();
		this.setTotalPages((int) Math.ceil((double) total / (double) pageable.getPageSize()));
		this.setPageNumber(pageable.getPageNumber());
	}

	/**
	 * 获取页码
	 *
	 * @return 页码
	 */
	public int getPageNumber() {
		return pageNumber;
	}

	/**
	 * 获取每页记录数
	 *
	 * @return 每页记录数
	 */
	public int getPageSize() {
		return this.pageSize;
	}


	public long getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(long totalPages) {
		this.totalPages = totalPages;
	}

	/**
	 * 获取内容
	 *
	 * @return 内容
	 */
	public List<T> getContent() {
		return content;
	}

	/**
	 * 获取总记录数
	 *
	 * @return 总记录数
	 */
	public long getTotal() {
		return total;
	}
}
